<template>
	<view @tap="openurl" class="content">
		<lazy image="/static/bg_launcher.png" :src="item.thumb"  mode="aspectFill" width="750rpx" :height="windowheight"></lazy>
		
		<view class="nav" v-show="show">
			<view class="href">点击跳转第三方应用</view>
		</view>
		<view class="time" v-if="time" @tap.stop="toindex">
			<piaoyiProgressBar canvasId="progressCanvas4" :progress="progress" backgroundColor="#EFEFF4"
			    progressBackgroundColor="#e99e07" :showText="true" textColor="#ffffff" :textSize="24" :height="6"
			    :isCircular="true" :diameter="100" ></piaoyiProgressBar>
			</view>
	</view>
</template>

<script>
	import lazy from "@/components/lazy-load.vue";
	import piaoyiProgressBar from '@/components/piaoyi-progress-bar.vue';
	export default {
		data() {
			return {
				guanggao: [],
				show: false,
				progress: 0,
				time: '',
				countTime: '',
				countTimeing: '',
				timer1: null,
				timer2: null,
				timer3: null,
				timing: '',
				windowheight: '100vh',
				item: '',
				index: 0,
			}
		},
		created() {
			this.windowheight = uni.getSystemInfoSync().windowHeight +'px';
		},
		onLoad() {
			this.$api.sendRequest({
				data:{
					service:'Guide.getGuide',
					token:uni.getStorageSync("token"),
				},
				success: res => {
					if(res.data.code == 0){
						var param = res.data.info[0];
						if(param.switch == 0){
							uni.reLaunch({
								url: "/pages/index/index"
							})
						}else{
							if(param.list.length > 0){
								this.guanggao = param.list;
								// param.time = 300;
								// this.time = param.time;
								// this.countTime = param.time;
								// this.timing = (param.time * 1000) / param.list.length;
								this.time = param.time * param.list.length;
								this.timing = (param.time * 1000);
								this.countTime = this.timing * 2;
								this.countTimeing = this.timing * 2;
								this.item = this.guanggao[0];
								this.start();
								this.show = true;
							}else{
								uni.reLaunch({
									url: "/pages/index/index"
								})
							}
						}
					}else{
						uni.reLaunch({
							url: "/pages/index/index"
						})
					}
				}
			});
		},
		methods: {
			openurl() {
				clearInterval(this.timer1);
				clearInterval(this.timer2);
				clearInterval(this.timer3);
				this.timer1 = null;
				this.timer2 = null;
				this.timer3 = null;
				var url = '/pages/index/index';
				uni.setStorageSync('src',this.item.href);
				uni.redirectTo({
					// url: '/pages/index/webview?backtype=1&url=' + url + '&src=' + this.item.href,
					url: '/pages/index/webview?backtype=1&url=' + url,
				})
			},
			start() {
				var that = this;
				this.timer1 = setInterval(() => {
					that.time--
					if (that.time <= 0) {
						clearInterval(that.timer1);
						clearInterval(that.timer2);
						clearInterval(that.timer3);
						this.timer1 = null;
						this.timer2 = null;
						this.timer3 = null;
						uni.reLaunch({
							url: "/pages/index/index"
						})
					}
				}, 1000)
				
				this.timer2 = setInterval(() => {
					if (that.time <= 0) {
						clearInterval(that.timer2);
						this.timer2 = null;
					}else{
						that.index += 1;
						that.item = that.guanggao[that.index];
					}
				}, that.timing);
				
					  
				this.timer3 = setInterval(() => {
					if (that.countTimeing <= 0) {
						clearInterval(that.timer3);
						this.timer3 = null;
					}else{
						that.countTimeing -= 100;
						that.progress = 100 - parseInt((parseFloat(that.countTimeing) / parseFloat(that.countTime) ) * 100 );
						// console.log(that.progress)
					}
				}, 100)
			},
			toindex() {
				clearInterval(this.timer1);
				clearInterval(this.timer2);
				clearInterval(this.timer3);
				this.timer1 = null;
				this.timer2 = null;
				this.timer3 = null;
				uni.reLaunch({
					url: "/pages/index/index"
				})
			}
		},
		components: {
			lazy,
			 piaoyiProgressBar
		}
	}
</script>

<style lang="scss" scoped>
	page{
		height: 100%;
	}
	.content{
		width: 750rpx;
		height: 100%;
	}
	.time {
		position: fixed;
		top: 60rpx;
		right: 20rpx;
		width: 100rpx;
		height: 100rpx;
		border-radius: 100rpx;
		background-color: #06060685;
		text-align: center;
		line-height: 100rpx;
		font-size: 36rpx;
		z-index: 999;
		color: #ffffff;
	}
	.nav{
		position: fixed;
		width: 750rpx;
		z-index: 999;
		bottom: 60rpx;
		
		.href{
			width: fit-content;
			color: #ffffff;
			background-color: #0000008f;
			margin: auto;
			border-radius: 60rpx;
			padding: 20rpx;
			font-size: 28rpx;
		}
		// padding: ;
	}
</style>